/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.login.plugin.profile.a;

import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.text.TextUtils;
import com.qihoo.gamecenter.sdk.common.IDispatcherCallback;
import com.qihoo.gamecenter.sdk.common.g.b;
import com.qihoo.gamecenter.sdk.login.plugin.d;
import com.qihoo.gamecenter.sdk.login.plugin.d.a;
import com.qihoo.gamecenter.sdk.login.plugin.h.e;
import com.qihoo.gamecenter.sdk.login.plugin.h.f;
import java.io.File;
import org.json.JSONException;
import org.json.JSONObject;

public class b implements g.b {
    private Context a;

    public b(Context paramContext) {
        this.a = paramContext;
    }

    public void a(Context paramContext, Intent paramIntent, IDispatcherCallback paramIDispatcherCallback) {
        e.a("Plugin.Profile.ModifyUserHeadShotTask", new Object[] { "begin ModifyUserHeadShotTask... " });
        new AsyncTask(paramIntent, paramIDispatcherCallback) {
            protected String a(Void[] paramArrayOfVoid) {
                String str1 = this.a.getStringExtra("head_shot");
                int i = b(str1);
                if (i != 0) {
                    str2 = f.a(i, "");
                    return str2;
                }
                String str2 = com.qihoo.gamecenter.sdk.login.plugin.profile.a.a(b.a(b.this), "b",
                        com.qihoo.gamecenter.sdk.login.plugin.h.a.a(this.a));
                String str3 = com.qihoo.gamecenter.sdk.login.plugin.d.a.a(b.a(b.this), str2, str1);
                return str3;
            }

            protected void a(String paramString) {
                e.a("Plugin.Profile.ModifyUserHeadShotTask", new Object[] { "ModifyUserHeadShotTask result is"
                        + paramString });
                if (!(TextUtils.isEmpty(paramString)))
                    try {
                        JSONObject localJSONObject1 = new JSONObject(paramString);
                        int i = localJSONObject1.getInt("errno");
                        e.a("Plugin.Profile.ModifyUserHeadShotTask", new Object[] { "result  is " + paramString });
                        e.a("Plugin.Profile.ModifyUserHeadShotTask", new Object[] { "errno  is " + i });
                        String str = a(i);
                        JSONObject localJSONObject2 = new JSONObject();
                        localJSONObject2.put("errno", i);
                        localJSONObject2.put("errmsg", str);
                        if (i == 0) {
                            localJSONObject2.put("avatar", localJSONObject1.optString("head_shot", ""));
                            paramString = localJSONObject2.toString();
                        }
                        else {
                            paramString = f.a(i, str);
                        }
                    } catch (JSONException localJSONException) {
                        e.a("Plugin.Profile.ModifyUserHeadShotTask",
                                new Object[] { "ModifyUserHeadShotTask exception  is "
                                        + localJSONException.getLocalizedMessage() });
                        paramString = f.a(400, "http request exception");
                    }
                else
                    paramString = f.a(400, "http request exception");
                this.b.onFinished(paramString);
            }

            private int b(String paramString) {
                if (TextUtils.isEmpty(paramString))
                    return 5030;
                File localFile = new File(paramString);
                if (!(localFile.exists()))
                    return 5030;
                return 0;
            }

            private String a(int paramInt) {
                switch (paramInt) {
                case 0:
                    return d.a(d.a.cR);
                case 5016:
                    return d.a(d.a.cS);
                case 5030:
                    return d.a(d.a.cT);
                case 5031:
                    return d.a(d.a.cU);
                case 5032:
                    return d.a(d.a.cV);
                case 5033:
                    return d.a(d.a.cW);
                case 5034:
                    return d.a(d.a.cX);
                case 5035:
                    return d.a(d.a.cY);
                case 60000:
                    return d.a(d.a.da);
                }
                return d.a(d.a.cY);
            }
        }.execute(new Void[0]);
    }
}